package com.kkb.controller;

import com.kkb.pojo.Team;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * @Author: 平川
 * @Description:
 * @Date Created in 2021-09-19 14:42
 * @Modified By:
 */
@Controller
public class ParamController {

    @RequestMapping("/str3")
    @ResponseBody
    public Map<String,Team> map1(){
        Map<String, Team> map = new HashMap<>();
        for (int i=0;i<5;i++){
            Team team = new Team();
            team.setTeamId(1+i);
            team.setTeamName("张"+i);
            team.setTeamDate(new Date());
            map.put(team.getTeamId()+"",team);
        }
        return map;
    }

    @RequestMapping("/str2")
    @ResponseBody
    public List<Team> list(){
        List<Team> list = new ArrayList<>();
        for (int i=0;i<5;i++){
            Team team = new Team();
            team.setTeamId(1+i);
            team.setTeamName("张"+i);
            list.add(team);
        }
        return list;
    }

    @RequestMapping("/str1")
    @ResponseBody
    public Team  tring(){
        Team team = new Team();
        team.setTeamName("张三");
        return team;
    }

    @RequestMapping("/list2")
    @ResponseBody
    public void List2(@RequestParam("hobby") List<String> hobby){
        for (String st: hobby){
            System.out.println(st);
        }
    }

    @RequestMapping("/list1")
    @ResponseBody
    public void List1(String[] hobby){
        for (String st: hobby){
            System.out.println(st);
        }
    }

    @RequestMapping("/date")
    @ResponseBody
    public void Date1(@RequestParam("id") Integer teamId,
                      @RequestParam("name") String teamName,
                      @RequestParam("date") @DateTimeFormat(pattern = "yyyy-MM-dd") Date  teamDate){
        System.out.println(teamId+" "+teamName+" "+teamDate);
    }

    @RequestMapping("/param/{id}/{name}")
    @ResponseBody
    public void URLparam(@PathVariable(value = "id",required = false) Integer teamId,
                         @PathVariable(value = "name",required = false) String teamName){
        System.out.println(teamId+" "+teamName);
    }

    @RequestMapping("/param2.do")
    @ResponseBody
    public void NameNot(@RequestParam(value = "id",required = false) Integer teamId,
                        @RequestParam(value = "name",required = false) String teamName){
        System.out.println(teamId+" "+teamName);
    }
}

